package org.zhangxiao.paladin2.admin.demo.core.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.zhangxiao.paladin2.common.util.SpringUtils;

@Configuration
public class MvcConfiguration implements WebMvcConfigurer {


    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT")
                .maxAge(3600);
    }


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        System.out.println("静态资源目录：file:" + SpringUtils.getJarDir() + "/common/");
        registry
                .addResourceHandler("/**")
                .addResourceLocations("file:" + SpringUtils.getJarDir() + "/static/");
        registry.addResourceHandler("/common/**").addResourceLocations("classpath:/common/");

        // registry.
        //         addResourceHandler("/api-doc/swagger-ui.html**")
        //         .addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
        // registry.
        //         addResourceHandler("/api-doc/webjars/**")
        //         .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
